<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="锁定仓库">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">
        .lockButton:hover{
            cursor: pointer;
        }
    </style>

    <script>
        jQuery(function () {

            $("#sure").click(function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            });

        });

        layui.use(['form', 'table'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table;

            table.render({
                id:'table',
                elem: '#table',
                url: "${baseUrl}organization/house/getNormList.action",
                where : {
                    time:(new Date()).valueOf()
                },
                cols: [[
                    {type:'numbers'},
                    {field: 'number', minWidth: 120, title: '仓库名称',style:"font-size:12px;",templet: '#nameBar'},
                    {width: 80, title: '操作',style:"font-size:12px;", templet: '#operBar'},
                ]]
                ,limit: Number.MAX_VALUE
                ,done : function () {
                    $(".lockButton").unbind().bind("click", function () {
                        let $tr = $(this).parents("tr");
                        let index = $tr.data("index");
                        let id = table.cache.table[index].id;
                        let lock = $(this).attr("lock");
                        let url = lock=="1" ? "${baseUrl}organization/house/unlock.action?id="+id : "${baseUrl}organization/house/lock.action?id="+id;
                        tipLoad(lock=="1" ? '解锁中...':'锁定中');
                        post(url,{}, function (res) {
                            closeLoading();
                            if (res.code == 1) {
                                if (lock == "1") {
                                    //解锁成功
                                    $tr.find(".lockIcon").removeClass("fa-lock").addClass("fa-unlock");
                                    $tr.find(".lockButton").css("color","#5FB878").html("锁定").attr("lock",0);
                                } else {
                                    //锁定成功
                                    $tr.find(".lockIcon").removeClass("fa-unlock").addClass("fa-lock");
                                    $tr.find(".lockButton").css("color","#FF5722").html("解锁").attr("lock",1);
                                }
                                callParentLock();
                            } else {
                                errTip(res.msg);
                            }
                        });

                    });
                }
            });

        });


        function callParentLock() {
            let allNumber = 0;
            let lockNum = 0;
            $(".lockButton").each(function () {
                if ($(this).attr("lock") == 1) {
                    lockNum++;
                }
                allNumber++;
            });

            window.parent.lockDialogCallBack(lockNum,allNumber);
        }
    </script>

</html:header>
<body style="background-color: #ffffff;">
<div>
    <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>

    <script type="text/html" id="nameBar" >
        <div class="nameDiv">
            {{# if(d.locking){ }}
            <i class="fa fa-lock lockIcon"></i>
            {{# }else{ }}
            <i class="fa fa-unlock lockIcon"></i>
            {{# } }}
            {{ d.store.name }} > {{ d.name }}
        </div>
    </script>

    <script type="text/html" id="operBar" >
        <div class="operDiv">
            {{# if(d.locking){ }}
            <a class="lockButton" style="color: #FF5722" lock="1">解锁</a>
            {{# }else{ }}
            <a class="lockButton" style="color: #5FB878" lock="0">锁定</a>
            {{# } }}
        </div>
    </script>
</div>
</body>

<html:loading/>
</html>